package com.tuozixuan.spring6.validation.method2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindException;
import org.springframework.validation.Validator;

@Service
public class MyService2 {

	@Autowired
	private Validator validator;

	public boolean validaPersonByValidator(User user) {
		BindException bindException = new BindException(user, user.getName());
		validator.validate(user, bindException);
		return bindException.hasErrors();
	}
}
